﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_DepartmentCheckUser : PX.MyPage
{
	#region 属性
	/// <summary>
	/// 用户控制类
	/// </summary>
	private PX.User.UserComponent clsUserComp = new PX.User.UserComponent();
	/// <summary>
	/// 提问者控制类
	/// </summary>
	private PX.Asker.Component clsAskerComp = new PX.Asker.Component();
	/// <summary>
	/// 专家控制类
	/// </summary>
	private PX.Expert.ExpertComponent clsExpertComp = new PX.Expert.ExpertComponent();

	#endregion 属性

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			BindGridView();
		}
	}

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);

		clsUserComp.page = Page;
		clsAskerComp.page = Page;
		clsExpertComp.page = Page;

		GrvInCheckUser.RowCommand += new GridViewCommandEventHandler(GrvInCheckUser_RowCommand);
		GrvInCheckUser.RowDataBound += new GridViewRowEventHandler(GrvInCheckUser_RowDataBound);
		LBtnFirst.Click += new EventHandler(LBtnFirst_Click);
		LBtnForward.Click += new EventHandler(LBtnForward_Click);
		LBtnNext.Click += new EventHandler(LBtnNext_Click);
		LBtnLast.Click += new EventHandler(LBtnLast_Click);
		LBtnClose.Click += new EventHandler(LBtnClose_Click);
		LBtnPass.Click += new EventHandler(LBtnPass_Click);
	}

	void LBtnPass_Click(object sender, EventArgs e)
	{
		Pass(Convert.ToInt32(LBtnPass.CommandArgument));

		PFloat.Visible = false;
		PShade.Visible = false;
	}

	void LBtnClose_Click(object sender, EventArgs e)
	{
		PFloat.Visible = false;
		PShade.Visible = false;
	}

	void LBtnLast_Click(object sender, EventArgs e)
	{
		GrvInCheckUser.PageIndex = GrvInCheckUser.PageCount - 1;

		BindGridView();
	}

	void LBtnNext_Click(object sender, EventArgs e)
	{
		GrvInCheckUser.PageIndex = GrvInCheckUser.PageIndex + 1;

		BindGridView();
	}

	void LBtnForward_Click(object sender, EventArgs e)
	{
		GrvInCheckUser.PageIndex = GrvInCheckUser.PageIndex - 1;

		BindGridView();
	}

	void LBtnFirst_Click(object sender, EventArgs e)
	{
		GrvInCheckUser.PageIndex = 0;

		BindGridView();
	}

	void GrvInCheckUser_RowDataBound(object sender, GridViewRowEventArgs e)
	{

	}

	void GrvInCheckUser_RowCommand(object sender, GridViewCommandEventArgs e)
	{
		if (e.CommandName == "Pass")
		{
			Pass(Convert.ToInt32(e.CommandArgument));
		}
		if (e.CommandName == "Detail")
		{
			PFloat.Visible = true;
			PShade.Visible = true;

			Detail(Convert.ToInt32(e.CommandArgument));

			LBtnPass.CommandArgument = e.CommandArgument.ToString();
		}
	}

	#region 控件数据绑定

	/// <summary>
	/// 绑定GridView显示待审核帐号
	/// </summary>
	private void BindGridView()
	{
		GrvInCheckUser.DataSource = clsUserComp.QueryInCheck(Convert.ToInt32(Session["LoginUserDepartmentID"]));
		GrvInCheckUser.DataKeyNames = new string[] { "ID" };
		GrvInCheckUser.DataBind();

		LabPageNumber.Text = "当前页码：【" + (GrvInCheckUser.PageIndex + 1) + "】  总页码：【" + GrvInCheckUser.PageCount + "】";

		if (GrvInCheckUser.PageIndex == 0)
		{
			LBtnFirst.Enabled = false;
			LBtnForward.Enabled = false;
		}
		else
		{
			LBtnFirst.Enabled = true;
			LBtnForward.Enabled = true;
		}

		if (GrvInCheckUser.PageIndex == GrvInCheckUser.PageCount - 1)
		{
			LBtnNext.Enabled = false;
			LBtnLast.Enabled = false;
		}
		else
		{
			LBtnNext.Enabled = true;
			LBtnLast.Enabled = true;
		}
	}

	#endregion 控件数据绑定

	/// <summary>
	/// 审核通过
	/// </summary>
	/// <param name="nUserID">需要审核的用户ID</param>
	private void Pass(int nUserID)
	{
		if (clsUserComp.Pass(nUserID))
		{
			Common.ShowMessageAlert.ShowMessage(Page, "审核通过！");
		}

		BindGridView();
	}

	/// <summary>
	/// 显示详细信息
	/// </summary>
	private void Detail(int nUserID)
	{
		if (clsAskerComp.Query(nUserID) != null)
		{
			MViewDetail.SetActiveView(ViewUser);
			ShowUserDetail(nUserID);
		}
		if (clsExpertComp.QueryByUserID(nUserID) != null)
		{
			MViewDetail.SetActiveView(ViewExpert);
			ShowExpertDetail(nUserID);
		}
	}

	/// <summary>
	/// 显示提问者详细信息
	/// </summary>
	/// <param name="nUserID"></param>
	private void ShowUserDetail(int nUserID)
	{
		PX.Asker.Entity clsAsker = new PX.Asker.Entity();

		clsAsker = clsAskerComp.Query(nUserID);
		UserUsername.Text = clsAsker.Username;
		UserUserGroup.Text = clsAsker.UserGroup;
		UserName.Text = clsAsker.Name;
		UserDepartment.Text = clsAsker.Department;
		UserEMail.Text = clsAsker.Email;
		UserPhone.Text = clsAsker.Phone;
	}

	/// <summary>
	/// 显示专家详细信息
	/// </summary>
	private void ShowExpertDetail(int nUserID)
	{
		PX.Expert.Expert clsExpert = new PX.Expert.Expert();

		clsExpert = clsExpertComp.QueryByUserID(nUserID);

		ExpertUsername.Text = clsExpert.Username;
		ExpertUserGroup.Text = clsExpert.UserGroup;
		ExpertName.Text = clsExpert.Name;
		ExpertDepartment.Text = clsExpert.Department;
		LabJob.Text = clsExpert.Job;

		//idImage.ImageUrl = "~/ShowImage.aspx?FileID=" + clsImageFile.ImageID.ToString();
		ImgPic.ImageUrl = "../ShowImage.aspx?FileID=" + clsExpert.ImageID.ToString();
		iFrameIntroduction.Attributes.Add("src", "../ShowImageFile.aspx?FileID=" + clsExpert.IntroductionID.ToString());
		//iFrameIntroduction.Attributes.Add("onload", "iFrameHeight('" + iFrameIntroduction.ClientID.ToString() + "')");
	}
}